class DidiliesController < ApplicationController
    
    layout 'default'
    before_filter :login_from_url_key, :only => [ :create ]
    before_filter :login_required, :except => [ :index, :show ]                
        
    ###################################
    # Get a list of all didilies
    # GET /didilies
    # GET /didilies.xml
    def index
        @didilies = Didily.find(:all, :include=>[:user,:relationship,:from_link,:to_link], :order => 'didilies.created_at DESC', :limit => 50)
        respond_to do |format|
            format.html # index.rhtml
            format.xml  { render :action => '../shared/didilies_xml.rxml', :layout=>false }
            format.rss  { render :action => '../shared/didilies_rss.rxml', :layout=>false }
            format.atom { render :action => '../shared/didilies_atom.rxml', :layout=>false }
            format.rdf  { render :action => '../shared/didilies_rdf.rxml', :layout=>false }
        end
    end
    
    ###################################
    # GET /didilies/1
    # GET /didilies/1.xml
    def show
        @didily = Didily.find(params[:id])
        respond_to do |format|
            format.html # show.rhtml
            format.xml  { @didilies = [@didily]; render :action => '../shared/didilies_xml.rxml', :layout=>false }
            format.rss  { @didilies = [@didily]; render :action => '../shared/didilies_rss.rxml', :layout=>false }
            format.atom { @didilies = [@didily]; render :action => '../shared/didilies_atom.rxml', :layout=>false }
            format.rdf  { @didilies = [@didily]; render :action => '../shared/didilies_rdf.rxml', :layout=>false }
        end
    end
    
    ###################################
    # GET /didilies/new
    def new
        @didily = Didily.new
    end
    
    ###################################
    # GET /didilies/1;edit
    def edit
        @didily = Didily.find(params[:id])
    end
    
    ###################################
    # POST /didilies
    # POST /didilies.xml
    def create
        @didily = Didily.new(params[:didily])
        @didily.user = current_user
        if @didily.save
            flash[:notice] = 'Didily was successfully created.'
            respond_to do |format|
                format.html { redirect_to didily_url(@didily) }
                format.xml  { head :created, :location => didily_url(@didily) }
            end
        else
            respond_to do |format|
                format.html { render :action => "new" }
                format.xml  { render :xml => @didily.errors.to_xml }
            end
        end
    end
    
    ###################################
    # PUT /didilies/1
    # PUT /didilies/1.xml
    def update
        @didily = Didily.find(params[:id])
        
        respond_to do |format|
            if @didily.update_attributes(params[:didily])
                flash[:notice] = 'Didily was successfully updated.'
                format.html { redirect_to didily_url(@didily) }
                format.xml  { head :ok }
            else
                format.html { render :action => "edit" }
                format.xml  { render :xml => @didily.errors.to_xml }
            end
        end
    end
    
    ###################################
    # DELETE /didilies/1
    # DELETE /didilies/1.xml
    def destroy
        @didily = Didily.find(params[:id])
        @didily.destroy
        
        respond_to do |format|
            format.html { redirect_to didilies_url }
            format.xml  { head :ok }
        end
    end
end
